package top.leyi.handle;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.leyi.exception.*;
import top.leyi.utils.Result;
import top.leyi.utils.ResultGenerator;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Allen
 * @date 2019/4/19
 * @desc 权限异常类
 */

@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler({TokenException.class})
    @ResponseBody
    public Result doTokenException(Exception e){
        return ResultGenerator.TOKEN_NOT_FOUND.getResult();
    }

    @ExceptionHandler({NoSuchAuthException.class})
    @ResponseBody
    public Result doNoSuchAuthExceptionHandle(NoSuchAuthException  e){

        return new Result(403,e.getMessage());
    }

    @ExceptionHandler({NotSuchUserIdException.class})
    @ResponseBody
    public Result notSuchUserIdException(Exception e){
        return new Result(400, "未找到此用户");
    }

    @ExceptionHandler({TalkNotFoundException.class})
    @ResponseBody
    public Result talkNotFoundException(Exception e){
        return new Result(400,"未找到此说说");
    }

    @ExceptionHandler({NoSuchClassException.class})
    @ResponseBody
    public Result noSuchClassExceptionHandle(Exception e){
        return  new Result(400,"未找到此班级");
    }

//    @ExceptionHandler({Exception.class})
//    @ResponseBody
//    public Result noIdeaException(Exception e){
//        return ResultGenerator.ERROR.getResult();
//    }

    @ExceptionHandler({WXLoginException.class})
    @ResponseBody
    public Result doWXLoginException(Exception e){
        return new Result(500, "无法正确获取openId，原因" + e.getMessage());
    }

    @ExceptionHandler({ClassNotSetException.class})
    @ResponseBody
    public Result doClassNotSetException(Exception e){
        return new Result(400, "班级-学院信息设置错误");
    }

    @ExceptionHandler({TokenSetException.class})
    @ResponseBody
    public Result doTokenSetException(Exception e){
        return new Result(400, e.getMessage());
    }


    @ExceptionHandler({ErrorFormatException.class})
    @ResponseBody
    public Result doErrorFormatException(Exception e){
        return new Result(400, "所需参数为json格式，请严格对照文档添加参数并格式进行规范");
    }


    @ExceptionHandler({IllegalDeleteException.class})
    @ResponseBody
    public Result doIllegalDeleteException(Exception e){
        return new Result(400, e.getMessage());
    }



    @ExceptionHandler({MutiSubmitException.class})
    @ResponseBody
    public Result doMutiSubmitException(Exception e) {
        return new Result(403, "请勿重复提交数据");
    }
}
